﻿using MetroDataApi.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace MetroDataApi.Controllers.Management
{
    public class UpdatePrjCenterController : ApiController
    {
        // GET api/updateprjcenter
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/updateprjcenter/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/updateprjcenter
        public bool Post([FromBody]string value)
        {
            JObject jsonData = JObject.Parse(value);
            int prjId = jsonData["prjId"].ToObject<int>();
            string center = jsonData["center"].ToString();
            var result = false;
            using (var db = new MetroDataDataContext())
            {
                var prj = db.Projects.SingleOrDefault(p => p.PrjId == prjId);
                if (prj != null)
                {
                    prj.Remark = center;
                    db.SubmitChanges();
                    return true;
                }
            }
            return result;

        }

        // PUT api/updateprjcenter/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/updateprjcenter/5
        public void Delete(int id)
        {
        }
    }
}
